package com.qf.springbootdemo02.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.qf.springbootdemo02.entity.ResultVO;
import com.qf.springbootdemo02.pojo.User;
import com.qf.springbootdemo02.service.IUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.view.InternalResourceViewResolver;

import java.util.List;

/**
 * @author q
 * @version V1.0
 * @date 2021/11/22
 **/
@RestController
@RequestMapping("/user")
@Api(tags = "UserController", value = "用户访问接口")
public class UserController {

    @Autowired
    private IUserService userService;

    /*
    value : 标题
    notes : 描述
    response : 响应类型，一般不写【由接口去推断】
 */
    @ApiOperation(value = "带条件分页查询用户", notes = "支持条件 与 姓名、手机的模糊匹配查询")
    /*
    ApiImplicitParam : 对入参参数进行描述
        name : 参数名称
        value : 参数描述
        required : 参数是否必须
        dataType : 参数类型
 */
    @ApiImplicitParams({@ApiImplicitParam(name = "pageNum", value = "页码", required = false, dataType = "Integer"),
                        @ApiImplicitParam(name = "pageSize", value = "页大小", required = false, dataType = "Integer"),
                        @ApiImplicitParam(name = "condition", value = "条件参数", required = false, dataType = "String")})
    @GetMapping("/findUserByConditionWithPage")
    public ResultVO<IPage> findUserByConditionWithPage(@RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                                                       @RequestParam(value = "pageSize", defaultValue = "5") Integer pageSize,
                                                       @RequestParam(value = "condition", defaultValue = "") String condition){
                                                        //语法：@RequestParam(value=”参数名”,required=”true/false”,defaultValue=””)
                                                        //value：参数名
                                                        //required：是否包含该参数，默认为true，表示该请求路径中必须包含该参数，如果不包含就报错。
                                                        //defaultValue：默认参数值，如果设置了该值，required=true将失效，自动为false,如果没有传该参数，就使用默认值
        ResultVO<IPage> userByConditionWithPage = userService.findUserByConditionWithPage(pageNum, pageSize, condition);
        //ModelAndView mav = new ModelAndView();
        //mav.addObject("pageUsers", userByConditionWithPage.getData());
        //mav.addObject("condition",condition);
        //mav.setViewName("user/user-list");
        //return mav;
        return userByConditionWithPage;
    }

}
